package gui;

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JSpinner;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.SpringLayout;

public class ServiceUIModifier extends AbstractViewPane {

	String[] enseignants= {"", "Exemple1", "Exemple2"}; 
	String[] groupes= {"", "Groupe1", "Groupe2"}; 
	int nbHeures= 10; 
	String[] typeHeures= {"", "Type1", "Type2"}; 
		
	ViewMode currentViewMode;
	
	public ServiceUIModifier(ViewMode v) {
		
		currentViewMode = v;
		
        String[] labels = {"Enseignant: ", "Groupe: ", "Nombre d'heures: ", "Type d'heures: "};
        int numPairs = labels.length;

        //ServiceBL serviceBL = ServiceBL.getInstance();
        //enseignants = serviceBL.getEnseignants();
        //groupes = serviceBL.getGroupes();
        //nbHeures = serviceBL.getNombreHeures();
        //typeHeures = serviceBL.getTypeHeure();
        

        //Create and populate the panel.
        JPanel p = new JPanel(new SpringLayout());
        
        JLabel l = new JLabel(labels[0], JLabel.TRAILING);
        p.add(l);
        JComboBox combo = new JComboBox (enseignants);
        if (currentViewMode == ViewMode.CONSULTATION) {
        	combo.setEnabled(false);
        }
        l.setLabelFor(combo);
        p.add(combo);
        

        l = new JLabel(labels[1], JLabel.TRAILING);
        p.add(l);
        combo = new JComboBox (groupes);
        if (currentViewMode == ViewMode.CONSULTATION) {
        	combo.setEnabled(false);
        }
        l.setLabelFor(combo);
        p.add(combo);

        l = new JLabel(labels[2], JLabel.TRAILING);
        p.add(l);
        SpinnerModel sm = new SpinnerNumberModel(nbHeures, 0, 100, 1);
        JSpinner spin = new JSpinner (sm);
        if (currentViewMode == ViewMode.CONSULTATION) {
        	spin.setEnabled(false);
        }
        l.setLabelFor(spin);
        p.add(spin);

        l = new JLabel(labels[3], JLabel.TRAILING);
        p.add(l);
        combo = new JComboBox (typeHeures);
        if (currentViewMode == ViewMode.CONSULTATION) {
        	combo.setEnabled(false);
        }
        l.setLabelFor(combo);
        p.add(combo);
        
        //Lay out the panel.
        SpringUtilities.makeCompactGrid(p,
                                        numPairs, 2, //rows, cols
                                        6, 6,        //initX, initY
                                        6, 6);       //xPad, yPad
        
        add(p, BorderLayout.NORTH);

        if (currentViewMode != ViewMode.CONSULTATION) {
        	// Mode modification - afficher les boutons
	        JPanel commandBox = new JPanel();
	        commandBox.add(new JButton("Enregistrer"));
	        drawCommandBox(commandBox);
        }
        
	}
	
	@Override
	public String getTitle() {
		// TODO Auto-generated method stub
		if (currentViewMode == ViewMode.CONSULTATION)
			return "Consultation d'un service";
		else if (currentViewMode == ViewMode.AJOUT)
			return "Ajout d'un service";
		else
			return "Modification d'un service";
	}

	@Override
	public boolean hasBeenModified() {
		return (currentViewMode != ViewMode.CONSULTATION);
	}

}
